//
//  TabBarViewController.m
//  News_lzz
//
//  Created by qianfeng01 on 15-6-14.
//  Copyright (c) 2015年 李忠. All rights reserved.
//

#import "TabBarViewController.h"
#import "MainViewController.h"

@interface TabBarViewController ()

@end

@implementation TabBarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self createTabBar];
}
/*
 #define kUrl @"http://api.sina.cn/sinago/list.json?channel=%@"
 #define kNewsToutiaoType  @"news_toutiao"
 #define kNewsSportstype   @"news_sports"
 #define kHdpicToutiaoType @"hdpic_toutiao"
 #define kHdpicFunnyType   @"hdpic_funny"
 #define kVideoFunnyType   @"video_funny"
 */
- (void)createTabBar {
/***********///需要传给子视图的类型;
    NSArray *newsArr = @[kNewsToutiaoType,kNewsSportstype];
    NSArray *picsArr = @[kHdpicToutiaoType,kHdpicFunnyType];
    NSArray *vidsArr = @[kVideoFunnyType];
    NSArray *mineArr = @[@""];
    NSArray *typeArr = @[newsArr,picsArr,vidsArr,mineArr];
/***********///子视图navigationItem上的button title
    NSArray *newsTitleArr = @[@"头条",@"娱乐",@"体育",@"财经",@"科技"];
    NSArray *picsTitleArr = @[@"图片",@"趣图",@"美图",@"故事"];
    NSArray *vidsTitleArr = @[@"精选",@"搞笑",@"现场",@"花絮"];
    NSArray *mineTitleArr = @[@""];
    NSArray *titleArr = @[newsTitleArr,picsTitleArr,vidsTitleArr,mineTitleArr];
/***********/
    NSArray *vcNameArr = @[@"NewsViewController",@"PicsViewController",@"VidsViewController",@"MineViewController"];
    NSArray *tabBarTitileArr = @[@"新闻",@"图片",@"视屏",@"我的"];
    NSArray *imageArr = @[@"tabbar_news",@"tabbar_picture",@"tabbar_video",@"tabbar_setting"];
    NSMutableArray *arr = [[NSMutableArray alloc] init];
/***********/
    
    for (NSInteger i=0; i<tabBarTitileArr.count; i++) {
        Class vcClass = NSClassFromString(vcNameArr[i]);
        MainViewController *mainVC = [[vcClass alloc] init];
        mainVC.typeArr = typeArr[i];
        mainVC.navigationItem.leftBarButtonItems = [self createNavigationItemWithTitle:titleArr[i] obj:mainVC];
        UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:mainVC];
        nav.title = tabBarTitileArr[i];//mainVC.title = tabBarTitileArr[i];
        nav.tabBarItem.image = [[UIImage imageNamed:imageArr[i]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        nav.tabBarItem.selectedImage = [[UIImage imageNamed:[NSString stringWithFormat:@"%@_hl",imageArr[i]]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        [arr addObject:nav];
    }
    self.viewControllers = arr;
}

- (NSArray *)createNavigationItemWithTitle:(NSArray *)titleArr obj:(MainViewController *)mainVC {
    NSMutableArray *arr = [[NSMutableArray alloc] init];
    UIBarButtonItem *space = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
    static NSInteger nForTag = 1;
    for (NSInteger i=0; i<titleArr.count; i++) {
        UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:titleArr[i] style:UIBarButtonItemStylePlain target:mainVC action:@selector(itemClick:)];
        item.tag = 100*nForTag+i+1;
        NSLog(@"%ld",item.tag);
        [arr addObject:space];
        [arr addObject:item];
    }
    nForTag++;
    [arr addObject:space];
    return [arr copy];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
